package linkedlist.test141;

import listbyorder.utils.ListNode;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/14 13:52
 */
public class Solution1 {

    public boolean hasCycle(ListNode head) {
        // 快慢指针
        if (head == null || head.next == null || head.next.next == null) return false;
        ListNode s = head, f = head;
        while (f != null && f.next != null) {
            s = s.next;
            f = f.next.next;
            if (s == f) {
                return true;
            }
        }
        return false;
    }
}
